/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Productos.java
 *
 * Created on 22-feb-2012, 15:07:04
 */
package desktop;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author cristopher
 */
public class Productos  extends javax.swing.JDialog  {
    Conex conexion;
    ResultSetTableModel modelo;
    String Query="select * from productos where id_producto=";
    String Query1="select * from productos where nombre=";
    String Query2="select * from productos where id_producto in(select id_producto from principio_activo where nombre=";
    int col,fil;
    Object editar= null;
    Object id_prod;
    /** Creates new form Productos */
    public Productos(java.awt.Frame parent, boolean modal) throws ClassNotFoundException, SQLException {
        super(parent, modal);
        initComponents();
        conexion = new Conex();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        panel_prods = new javax.swing.JPanel();
        grupo_pest = new javax.swing.JTabbedPane();
        ing_prods = new javax.swing.JScrollPane();
        ing_panel = new javax.swing.JPanel();
        label1_ing_prods = new javax.swing.JLabel();
        nombre_ing = new javax.swing.JTextField();
        label2_ing_prods = new javax.swing.JLabel();
        cantidad_ing = new javax.swing.JTextField();
        label3_ing_prods = new javax.swing.JLabel();
        prec_uni = new javax.swing.JTextField();
        ingresar_btn = new javax.swing.JButton();
        limpiar_btn = new javax.swing.JButton();
        Bus_prods = new javax.swing.JScrollPane();
        bus_panel = new javax.swing.JPanel();
        jLabel1_edit = new javax.swing.JLabel();
        jTextField1_edit = new javax.swing.JTextField();
        jLabel2_edit = new javax.swing.JLabel();
        jTextField2_edit = new javax.swing.JTextField();
        jButton1_edit = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1_edit = new javax.swing.JTable();
        jButton2_edit = new javax.swing.JButton();
        jButton3_edit = new javax.swing.JButton();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        box = new javax.swing.JComboBox();
        titulo_prod = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        panel_prods.setBackground(new java.awt.Color(156, 203, 216));

        label1_ing_prods.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        label1_ing_prods.setText("Nombre del Producto");
        label1_ing_prods.setToolTipText("");

        nombre_ing.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nombre_ingActionPerformed(evt);
            }
        });

        label2_ing_prods.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        label2_ing_prods.setText("Cantidad");
        label2_ing_prods.setToolTipText("");

        cantidad_ing.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cantidad_ingActionPerformed(evt);
            }
        });
        cantidad_ing.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                cantidad_ingKeyTyped(evt);
            }
        });

        label3_ing_prods.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        label3_ing_prods.setText("Precio Unitario");

        prec_uni.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                prec_uniKeyTyped(evt);
            }
        });

        ingresar_btn.setText("Ingresar");
        ingresar_btn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ingresar_btnActionPerformed(evt);
            }
        });

        limpiar_btn.setText("Limpiar");
        limpiar_btn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                limpiar_btnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout ing_panelLayout = new javax.swing.GroupLayout(ing_panel);
        ing_panel.setLayout(ing_panelLayout);
        ing_panelLayout.setHorizontalGroup(
            ing_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ing_panelLayout.createSequentialGroup()
                .addGroup(ing_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(ing_panelLayout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addGroup(ing_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(label3_ing_prods, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
                            .addComponent(label2_ing_prods, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)))
                    .addGroup(ing_panelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(label1_ing_prods, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE)))
                .addGap(18, 18, 18)
                .addGroup(ing_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(ing_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(prec_uni, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(cantidad_ing, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
                    .addComponent(nombre_ing, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(264, 264, 264))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ing_panelLayout.createSequentialGroup()
                .addContainerGap(166, Short.MAX_VALUE)
                .addComponent(limpiar_btn, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(137, 137, 137)
                .addComponent(ingresar_btn, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(221, 221, 221))
        );
        ing_panelLayout.setVerticalGroup(
            ing_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ing_panelLayout.createSequentialGroup()
                .addContainerGap(50, Short.MAX_VALUE)
                .addGroup(ing_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label1_ing_prods, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(nombre_ing, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(29, 29, 29)
                .addGroup(ing_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label2_ing_prods, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cantidad_ing, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(36, 36, 36)
                .addGroup(ing_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(label3_ing_prods)
                    .addComponent(prec_uni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(133, 133, 133)
                .addGroup(ing_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ingresar_btn, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(limpiar_btn, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(45, 45, 45))
        );

        ing_prods.setViewportView(ing_panel);

        grupo_pest.addTab("Ingreso de Productos", ing_prods);

        bus_panel.setPreferredSize(new java.awt.Dimension(700, 598));

        jLabel1_edit.setText("Ingrese Código  Producto");

        jTextField1_edit.setEditable(false);
        jTextField1_edit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1_editActionPerformed(evt);
            }
        });
        jTextField1_edit.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField1_editKeyTyped(evt);
            }
        });

        jLabel2_edit.setText("Ingrese Nombre Producto");

        jTextField2_edit.setEditable(false);

        jButton1_edit.setText("Buscar");
        jButton1_edit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1_editActionPerformed(evt);
            }
        });

        jTable1_edit.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Id Producto", "Nombre", "Stock", "Precio"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.Integer.class, java.lang.Double.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1_edit.getTableHeader().setResizingAllowed(false);
        jTable1_edit.getTableHeader().setReorderingAllowed(false);
        jTable1_edit.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1_editMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1_edit);

        jButton2_edit.setText("Limpiar");
        jButton2_edit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2_editActionPerformed(evt);
            }
        });

        jButton3_edit.setText("Editar");
        jButton3_edit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3_editActionPerformed(evt);
            }
        });

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton1ActionPerformed(evt);
            }
        });

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton2ActionPerformed(evt);
            }
        });

        buttonGroup1.add(jRadioButton3);
        jRadioButton3.setText("Principio Activo");
        jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButton3ActionPerformed(evt);
            }
        });

        box.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        box.setEnabled(false);

        javax.swing.GroupLayout bus_panelLayout = new javax.swing.GroupLayout(bus_panel);
        bus_panel.setLayout(bus_panelLayout);
        bus_panelLayout.setHorizontalGroup(
            bus_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, bus_panelLayout.createSequentialGroup()
                .addContainerGap(190, Short.MAX_VALUE)
                .addComponent(jButton2_edit)
                .addGap(168, 168, 168)
                .addComponent(jButton3_edit)
                .addGap(227, 227, 227))
            .addGroup(bus_panelLayout.createSequentialGroup()
                .addGap(16, 16, 16)
                .addGroup(bus_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 622, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(bus_panelLayout.createSequentialGroup()
                        .addComponent(jRadioButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(bus_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1_edit, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextField1_edit, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(bus_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(bus_panelLayout.createSequentialGroup()
                                .addComponent(jRadioButton2)
                                .addGap(18, 18, 18)
                                .addComponent(jLabel2_edit, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(bus_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jButton1_edit, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jTextField2_edit, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(36, 36, 36)
                        .addGroup(bus_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(bus_panelLayout.createSequentialGroup()
                                .addGap(21, 21, 21)
                                .addComponent(box, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jRadioButton3))))
                .addContainerGap(62, Short.MAX_VALUE))
        );
        bus_panelLayout.setVerticalGroup(
            bus_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(bus_panelLayout.createSequentialGroup()
                .addGroup(bus_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(bus_panelLayout.createSequentialGroup()
                        .addGroup(bus_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(bus_panelLayout.createSequentialGroup()
                                .addGap(16, 16, 16)
                                .addComponent(jRadioButton1))
                            .addGroup(bus_panelLayout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(bus_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jRadioButton2)
                                    .addComponent(jLabel1_edit, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(bus_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel2_edit, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jRadioButton3)))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(bus_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextField2_edit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(box, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(47, 47, 47)
                        .addComponent(jButton1_edit, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(bus_panelLayout.createSequentialGroup()
                        .addGap(47, 47, 47)
                        .addComponent(jTextField1_edit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(48, 48, 48)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29)
                .addGroup(bus_panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3_edit)
                    .addComponent(jButton2_edit))
                .addContainerGap(195, Short.MAX_VALUE))
        );

        Bus_prods.setViewportView(bus_panel);

        grupo_pest.addTab("Busqueda  y Edición de productos", Bus_prods);

        javax.swing.GroupLayout panel_prodsLayout = new javax.swing.GroupLayout(panel_prods);
        panel_prods.setLayout(panel_prodsLayout);
        panel_prodsLayout.setHorizontalGroup(
            panel_prodsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_prodsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(grupo_pest, javax.swing.GroupLayout.DEFAULT_SIZE, 682, Short.MAX_VALUE)
                .addContainerGap())
        );
        panel_prodsLayout.setVerticalGroup(
            panel_prodsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panel_prodsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(grupo_pest, javax.swing.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE)
                .addContainerGap())
        );

        titulo_prod.setFont(new java.awt.Font("Tahoma", 1, 18));
        titulo_prod.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        titulo_prod.setText("Administración de Productos");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(205, 205, 205)
                        .addComponent(titulo_prod, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(panel_prods, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(titulo_prod, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(44, 44, 44)
                .addComponent(panel_prods, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-730)/2, (screenSize.height-570)/2, 730, 570);
    }// </editor-fold>//GEN-END:initComponents

private void nombre_ingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nombre_ingActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_nombre_ingActionPerformed

private void cantidad_ingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cantidad_ingActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_cantidad_ingActionPerformed

private void ingresar_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ingresar_btnActionPerformed
    // TODO add your handling code here:
    
    if(!this.nombre_ing.getText().isEmpty() && !this.cantidad_ing.getText().isEmpty() && !this.prec_uni.getText().isEmpty())
    {
        String nombre_prod = this.nombre_ing.getText();
        int cantidad = Integer.parseInt(this.cantidad_ing.getText());
        int precio_u = Integer.parseInt(this.prec_uni.getText());
            try {
                conexion.insertar_prod(nombre_prod, cantidad, precio_u);
                } catch (SQLException ex) {
                Logger.getLogger(Productos.class.getName()).log(Level.SEVERE, null, ex);
                }
   
        System.out.println(nombre_prod+", "+cantidad+", "+precio_u);
        JOptionPane.showMessageDialog(null, "elemento Ingresado Correctamente", "Exito",JOptionPane.INFORMATION_MESSAGE);
    }
    else
    {
         JOptionPane.showMessageDialog(null, "error Ingrese Elementos", "Error",JOptionPane.ERROR_MESSAGE);
    }
    
}//GEN-LAST:event_ingresar_btnActionPerformed

private void jButton1_editActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1_editActionPerformed
    // TODO add your handling code here:
    if(this.jRadioButton1.isSelected() && !this.jTextField1_edit.getText().isEmpty())
    {
            try {
                String id = this.jTextField1_edit.getText();
                String busqueda_id = Query + id;
                modelo = new ResultSetTableModel(Conex.CONTROLADOR, Conex.URL_BASEDATOS, Conex.NOMBRE_USUARIO, Conex.CONTRA, busqueda_id);
                this.jTable1_edit.setModel(modelo);
            } catch (SQLException ex) {
                Logger.getLogger(Productos.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Productos.class.getName()).log(Level.SEVERE, null, ex);
            }
    }
    if(this.jRadioButton2.isSelected() && !this.jTextField2_edit.getText().isEmpty())
    {
            try {
                String nombre = this.jTextField2_edit.getText();
                String busqueda_nombre = Query1+"'"+nombre+"'";
                modelo = new ResultSetTableModel(Conex.CONTROLADOR, Conex.URL_BASEDATOS, Conex.NOMBRE_USUARIO, Conex.CONTRA, busqueda_nombre);
                this.jTable1_edit.setModel(modelo);
            } catch (SQLException ex) {
                Logger.getLogger(Productos.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Productos.class.getName()).log(Level.SEVERE, null, ex);
            }
    }
     if(this.jRadioButton3.isSelected())
    {
            try {
                String principio = this.box.getSelectedItem().toString();
                String busqueda_activo = Query2+"'"+principio+"')";
                modelo = new ResultSetTableModel(Conex.CONTROLADOR, Conex.URL_BASEDATOS, Conex.NOMBRE_USUARIO, Conex.CONTRA, busqueda_activo);
                this.jTable1_edit.setModel(modelo);
            } catch (SQLException ex) {
                Logger.getLogger(Productos.class.getName()).log(Level.SEVERE, null, ex);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Productos.class.getName()).log(Level.SEVERE, null, ex);
            }
    }


//    if(this.jRadioButton2.isSelected())
//    {
//        String nom= this.jTextField2_edit.getText();
//        System.out.println(""+nom);
//    }
    

}//GEN-LAST:event_jButton1_editActionPerformed

private void jTextField1_editActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1_editActionPerformed
    // TODO add your handling code here:
    
}//GEN-LAST:event_jTextField1_editActionPerformed

private void limpiar_btnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_limpiar_btnActionPerformed
    // TODO add your handling code here:
    this.cantidad_ing.setText("");
    this.nombre_ing.setText("");
    this.prec_uni.setText("");
}//GEN-LAST:event_limpiar_btnActionPerformed

private void cantidad_ingKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_cantidad_ingKeyTyped
    // TODO add your handling code here:
    char caracter = evt.getKeyChar();

      // Verificar si la tecla pulsada no es un digito
      if(((caracter < '0') ||
         (caracter > '9')) &&
         (caracter != '\b' /*corresponde a BACK_SPACE*/))
      {
         evt.consume();  // ignorar el evento de teclado
      }
}//GEN-LAST:event_cantidad_ingKeyTyped

private void prec_uniKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_prec_uniKeyTyped
    // TODO add your handling code here:
    char caracter = evt.getKeyChar();

      // Verificar si la tecla pulsada no es un digito
      if(((caracter < '0') ||
         (caracter > '9')) &&
         (caracter != '\b' /*corresponde a BACK_SPACE*/))
      {
         evt.consume();  // ignorar el evento de teclado
      }

}//GEN-LAST:event_prec_uniKeyTyped

private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
    // TODO add your handling code here:
    this.jTextField2_edit.setEditable(false);
    this.jTextField2_edit.setText("");
    this.jTextField1_edit.setEditable(true);
    this.box.setEnabled(false);
}//GEN-LAST:event_jRadioButton1ActionPerformed

private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
    // TODO add your handling code here:
     this.jTextField1_edit.setEditable(false);
     this.jTextField1_edit.setText("");
     this.jTextField2_edit.setEditable(true);
     this.box.setEnabled(false);
}//GEN-LAST:event_jRadioButton2ActionPerformed

private void jButton2_editActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2_editActionPerformed
    // TODO add your handling code here:
    this.jTextField1_edit.setText("");
    this.jTextField2_edit.setText("");
    
   
}//GEN-LAST:event_jButton2_editActionPerformed

private void jTextField1_editKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1_editKeyTyped
    // TODO add your handling code here:
     char caracter = evt.getKeyChar();

      // Verificar si la tecla pulsada no es un digito
      if(((caracter < '0') ||
         (caracter > '9')) &&
         (caracter != '\b' /*corresponde a BACK_SPACE*/))
      {
         evt.consume();  // ignorar el evento de teclado
      }
}//GEN-LAST:event_jTextField1_editKeyTyped

private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton3ActionPerformed
    // TODO add your handling code here:
    this.box.setEnabled(true);
    this.jTextField1_edit.setEditable(false);
    this.jTextField1_edit.setText("");
    this.jTextField2_edit.setEditable(false);
    this.jTextField2_edit.setText("");

}//GEN-LAST:event_jRadioButton3ActionPerformed

private void jButton3_editActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3_editActionPerformed
    // TODO add your handling code here:
    if(this.editar!= null && col!=0 && col!=1)
    {

        String new_Dat=JOptionPane.showInputDialog(null, "Ingrese Dato", "Editar", JOptionPane.INFORMATION_MESSAGE);
        int new_num= Integer.parseInt(new_Dat);
        System.out.println(new_num);
        if(col==2 && new_Dat!=null) //stock
        {
                try {
                    conexion.editar_prod_stock(new_num, id_prod);
                    JOptionPane.showMessageDialog(null, "edicion correcta", "ok", JOptionPane.INFORMATION_MESSAGE);
                    this.jTable1_edit.setModel(modelo);
                    this.jTable1_edit.repaint();
                } catch (SQLException ex) {
                    Logger.getLogger(Productos.class.getName()).log(Level.SEVERE, null, ex);
                }
        }else if(col==3 && new_Dat!=null) //stock
        {
                try {
                    conexion.editar_prod_precio(new_num, id_prod);
                    JOptionPane.showMessageDialog(null, "edicion correcta", "ok", JOptionPane.INFORMATION_MESSAGE);
                    this.jTable1_edit.setModel(modelo);
                    this.jTable1_edit.repaint();
                } catch (SQLException ex) {
                    Logger.getLogger(Productos.class.getName()).log(Level.SEVERE, null, ex);
                }
        }
        else
        {
           JOptionPane.showMessageDialog(null, "ingrese dato", "error", JOptionPane.WARNING_MESSAGE); 
        }
        
        
        
        
    }
    else
    {
        JOptionPane.showMessageDialog(null, "no se puede editar...", "error", 2);
    }

    
}//GEN-LAST:event_jButton3_editActionPerformed

private void jTable1_editMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1_editMouseClicked
    // TODO add your handling code here:
    col=this.jTable1_edit.getSelectedColumn();
    fil=this.jTable1_edit.getSelectedRow();


    this.editar=this.jTable1_edit.getValueAt(fil, col);
    this.id_prod=this.jTable1_edit.getValueAt(fil, 0);
    
}//GEN-LAST:event_jTable1_editMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Productos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Productos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Productos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Productos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                try {
                    Productos dialog = new Productos(new javax.swing.JFrame(), true);
                    dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                        @Override
                        public void windowClosing(java.awt.event.WindowEvent e) {
                            System.exit(0);
                        }
                    });
                    dialog.setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(Productos.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(Productos.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane Bus_prods;
    public javax.swing.JComboBox box;
    private javax.swing.JPanel bus_panel;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JTextField cantidad_ing;
    private javax.swing.JTabbedPane grupo_pest;
    private javax.swing.JPanel ing_panel;
    private javax.swing.JScrollPane ing_prods;
    private javax.swing.JButton ingresar_btn;
    private javax.swing.JButton jButton1_edit;
    private javax.swing.JButton jButton2_edit;
    private javax.swing.JButton jButton3_edit;
    private javax.swing.JLabel jLabel1_edit;
    private javax.swing.JLabel jLabel2_edit;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1_edit;
    private javax.swing.JTextField jTextField1_edit;
    private javax.swing.JTextField jTextField2_edit;
    private javax.swing.JLabel label1_ing_prods;
    private javax.swing.JLabel label2_ing_prods;
    private javax.swing.JLabel label3_ing_prods;
    private javax.swing.JButton limpiar_btn;
    private javax.swing.JTextField nombre_ing;
    private javax.swing.JPanel panel_prods;
    private javax.swing.JTextField prec_uni;
    private javax.swing.JLabel titulo_prod;
    // End of variables declaration//GEN-END:variables
}
// while (this.cantidad_ing.getText().isEmpty() && this.prec_uni.getText().isEmpty())
//                {
//                    this.prec_total.setText("0");
//                }
//                while (!this.cantidad_ing.getText().isEmpty() && !this.prec_uni.getText().isEmpty())
//                {
//                    int cant =Integer.parseInt(this.cantidad_ing.getText());
//                    int unit =Integer.parseInt(this.prec_uni.getText());
//                    int total = cant*unit;
//                    this.prec_total.setText(total+"");
//                }